﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FCTC_Web.Models;
using DAL;
using FCTC_Web.Utilities;

namespace FCTC_Web.Controllers.Business.BusinessModel
{


    public class VehicleBusiness : BusinessBase
    {
        public static VehicleBusiness _ins = new VehicleBusiness();
        public static VehicleBusiness Ins
        {
            get { return _ins; }
        }

        public List<Vehicle> ExchangeVehicleList
        {
            get { return CH.GetAllData<Vehicle>(); }
        }

        public List<Vehicle> LatestVehicles
        {
            get { return CH.GetAllData<Vehicle>().OrderByDescending(i=>i.EnrollmentDate).ToList(); }
        }

        public List<Vehicle> Cars
        {
            get { return CH.GetAllData<Vehicle>(i => i.Category == "轿车").OrderByDescending(i => i.Sequense).ToList(); }
        }

        public List<Vehicle> BusinessVehicle
        {
            get { return CH.GetAllData<Vehicle>(i => i.Category == "商务车").OrderByDescending(i => i.Sequense).ToList(); }
        }

        public List<Vehicle> Transportion
        {
            get { return CH.GetAllData<Vehicle>(i => i.Category == "客车").OrderByDescending(i => i.Sequense).ToList(); }
        }
        public List<Vehicle> SUV
        {
            get { return CH.GetAllData<Vehicle>(i => i.Category == "越野车").OrderByDescending(i => i.Sequense).ToList(); }
        }

        public List<Vehicle> SpecialOffers
        {
            get { return CH.GetAllData<Vehicle>(i=>i.SpecialOffer==true).OrderByDescending(i=>i.Sequense).ToList(); }
        }

        public Page<Vehicle> VehicleSearchRearchResult
        {
            get;
            set;
        }
    }

    public class VehicleDetailBusiness : BusinessBase
    {
        public VehicleDetailBusiness(int? i)
        {
            Vehicle = CH.GetDataById<Vehicle>(i);
           
            if (Vehicle == null)
                throw new Exception("该车辆不存在");

            OwnerShop = CH.GetDataById<Shop>(Vehicle.ShopID);
        }

        public Shop OwnerShop { get; set; }

        public Vehicle Vehicle { get; set; }
    }


}